﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace IntroToMef
{

    class UsingAnAssemblyCatalog
    {
        [ImportMany]
        public IEnumerable<ILogger> Loggers { set; get; }

        [Import]
        public IPerson Persons { set; get; }



        internal void Run()
        {
            Compose();
            foreach (var logger in Loggers)
            {
                logger.Log("Hi");
            }
            //foreach (var person in Persons)
            //{
            //    person.Say();
            //}
            Persons.Say();

        }

        private void Compose()
        {
            var assemblyCatalog = new AssemblyCatalog(GetType().Assembly);
            var container = new CompositionContainer(assemblyCatalog);

            container.ComposeParts(this);
        }
    }
}
